public class Work2 {
    public static double avg(int[] array) {
        int sum = 0;
        for (int j : array) {
            sum += j;
        }
        return (double) sum / (double) array.length;
    }

    public static void main(String[] args) {
        //实现一个方法 avg, 以数组为参数, 求数组中所有元素的平均值(注意方法的返回值类型).
        int[] array = {1, 2, 3, 4, 5};
        System.out.println(avg(array));
    }
}
